package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.FriendRequest;
import com.ruoyi.system.domain.vo.FriendRelationshipVO;
import com.ruoyi.system.domain.vo.FriendRequestVO;
import com.ruoyi.system.domain.vo.SysUserVO;
import com.ruoyi.system.service.IFriendRequestService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FriendRelationship;
import com.ruoyi.system.service.IFriendRelationshipService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 好友关系Controller
 * 
 * @author ruoyi
 * @date 2025-09-17
 */
@RestController
@RequestMapping("/system/relationship")
public class FriendRelationshipController extends BaseController<IFriendRelationshipService, FriendRelationship, FriendRelationshipVO>
{
    @Autowired
    private IFriendRelationshipService friendRelationshipService;

    @Autowired
    private ISysUserService sysUserService;


    /**
     * 查询用户的好友列表
     */
    @PreAuthorize("@ss.hasPermi('system:chat:list')")
    @PostMapping("/queryFriendListByUserId")
    public AjaxResult queryFriendListByUserId(@RequestBody SysUserVO queryVO) {
        List<SysUserVO> list = sysUserService.queryFriendListByUserId(queryVO);
        return success(list);
    }


    /**
     * 查询系统中的用户
     */
    @PreAuthorize("@ss.hasPermi('system:chat:list')")
    @PostMapping("/queryUserList")
    public AjaxResult queryUserList(@RequestBody SysUserVO queryVO) {
        List<SysUserVO> list = sysUserService.queryUserList(queryVO);
        return success(list);
    }



    /**
     * 查询好友关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:relationship:list')")
    @GetMapping("/list")
    public TableDataInfo list(FriendRelationship friendRelationship)
    {
        startPage();
        List<FriendRelationship> list = friendRelationshipService.selectFriendRelationshipList(friendRelationship);
        return getDataTable(list);
    }

    /**
     * 导出好友关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:relationship:export')")
    @Log(title = "好友关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FriendRelationship friendRelationship)
    {
        List<FriendRelationship> list = friendRelationshipService.selectFriendRelationshipList(friendRelationship);
        ExcelUtil<FriendRelationship> util = new ExcelUtil<FriendRelationship>(FriendRelationship.class);
        util.exportExcel(response, list, "好友关系数据");
    }

    /**
     * 获取好友关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:relationship:query')")
    @GetMapping(value = "/{relationshipId}")
    public AjaxResult getInfo(@PathVariable("relationshipId") Long relationshipId)
    {
        return success(friendRelationshipService.selectFriendRelationshipByRelationshipId(relationshipId));
    }

    /**
     * 新增好友关系
     */
    @PreAuthorize("@ss.hasPermi('system:relationship:add')")
    @Log(title = "好友关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FriendRelationship friendRelationship)
    {
        return toAjax(friendRelationshipService.insertFriendRelationship(friendRelationship));
    }

    /**
     * 修改好友关系
     */
    @PreAuthorize("@ss.hasPermi('system:relationship:edit')")
    @Log(title = "好友关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FriendRelationship friendRelationship)
    {
        return toAjax(friendRelationshipService.updateFriendRelationship(friendRelationship));
    }

    /**
     * 删除好友关系
     */
    @PreAuthorize("@ss.hasPermi('system:relationship:remove')")
    @Log(title = "好友关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{relationshipIds}")
    public AjaxResult remove(@PathVariable Long[] relationshipIds)
    {
        return toAjax(friendRelationshipService.deleteFriendRelationshipByRelationshipIds(relationshipIds));
    }
}
